<?php require_once(dirname(__FILE__).'/../include/config.inc.php'); 

require_once "function.php";

/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/


$userInfo="";

if(isset($uid)){
		//有session 从数据库中读取用户名信息
	 	//$openid_str=$_SESSION['openid'];
		$row = $dosql->GetOne("SELECT * FROM `#@__user` WHERE id='$uid'");
			if(is_array($row) && isset($row['id'])){
				// 返回用户 id 
				$userInfo=$row;
			}
}

?>

<!DOCTYPE html>

<html>

<head>

<title>添加地址-<?php echo $cfg_webname;?></title>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<meta name="description" content="<?php echo $cfg_webname;?>">

<link rel="stylesheet" href="lib/weui.min.css">

<link rel="stylesheet" href="css/jquery-weui.css">

<link rel="stylesheet" href="css/font-awesome.min.css">

<link rel="stylesheet" href="css/demos.css">

</head>
<?php 
//字段显示
if($call=="member"){
	$tit="修改联系方式";
	$calurl="member.php";
}elseif($call=="apply"){
	$tit="修改联系方式";
	$calurl="apply.php?type=".$type;
}

$op_str='<div class="sub_btn"></div>';
$crm_init=$dosql->GetOne("select * from `#@__crm`  where uid='$uid'  ");
if( is_array($crm_init) &&  isset($crm_init['id']) ){
			if($crm_init['checkinfo']=='false'){
				$op_str='<a href="javascript:;" class="weui-btn weui-btn_primary" onclick="cfm_msg();return false;">保存地址</a></div>';
			}
}

?>





<body ontouchstart>

<div class="top">
<div class="user_top">
	<div class="user_top_conn">
    <img src="<?php echo $userInfo['headimgurl']?>"/>
    <p><?php echo $userInfo['nickname']?></p>
    </div>
</div>

 </div>

<div class="main add_top_bg">

  <div class="weui-cells__title"><i class="fa fa-id-card-o" aria-hidden="true"></i> <?php echo $tit;?></div>

  <div class="weui-cells weui-cells_form">

   <form name="form" id="form" method="post" action="">

    <div class="weui-cell">

      <div class="weui-cell__hd">

        <label class="weui-label"><i class="fa fa-building-o" aria-hidden="true"></i>单位：</label>

      </div>

      <div class="weui-cell__bd">

        <input class="weui-input"  name="school" id="school" type="text"  value="<?php echo $userInfo['school']?>">

      </div>

    </div>

    <div class="weui-cell">

      <div class="weui-cell__hd">

        <label class="weui-label"><i class="fa fa-user-circle-o" aria-hidden="true"></i>联系人：</label>

      </div>

      <div class="weui-cell__bd">

        <input class="weui-input" name="truename" id="truename" type="text"  value="<?php echo $userInfo['truename']?>">

      </div>

    </div>

    <div class="weui-cell ">

      <div class="weui-cell__hd">

        <label class="weui-label"><i class="fa fa-mobile" aria-hidden="true"></i>手机号</label>

      </div>

      <div class="weui-cell__bd">

        <input class="weui-input" name="mobile" id="mobile" type="text"   value="<?php echo $userInfo['mobile']?>">

      </div>

    </div>

    <div class="weui-cell">

      <div class="weui-cell__hd">

        <label class="weui-label"><i class="fa fa-map-marker" aria-hidden="true"></i> 地址：</label>

      </div>

      <div class="weui-cell__bd">

        <input class="weui-input" type="text" name="address"  id="address"  value="<?php echo $userInfo['address']?>">

      </div>

    </div>

     <input type="hidden" name="action" id="action" value="add" />

     <input type="hidden" name="uid" id="uid" value="<?php echo $uid?>" />

    </form>

  </div>

</div>
<?php echo $op_str;?>
<div class="clear"></div>

<script src="lib/jquery-2.1.4.js"></script> 

<script src="lib/fastclick.js"></script> 

<script>

  $(function() {

    FastClick.attach(document.body);

  });

</script> 

<script src="js/jquery-weui.js"></script> 

<script src="js/city-picker.js"></script> 

<script>



function cfm_msg()
{
	if($("#school").val() == "")
	{
		$.toast("单位不能为空","forbidden");
		$("#school").focus();
		return false;
	}

	if($("#truename").val() == "")
	{
		$.toast("联系人不能为空","forbidden");
		$("#truename").focus();
		return false;
	}

	if($("#mobile").val() == "")
	{
		$.toast("手机号码不能为空","forbidden");
		$("#mobile").focus();
		return false;
	}

	if($("#address").val() == "")
	{
		$.toast("地址不能为空","forbidden");
		$("#address").focus();
		return false;
	}
	$("#form").submit();
}


    </script>

 
 <?php

 //留言内容处理



if(isset($action) and $action=='add'){

	if(empty($school) or

	   empty($truename) or

	   empty($mobile))

	{

		header('location:user.php');

		exit();

	}
	$school		=htmlspecialchars($school);
	$truename	=htmlspecialchars($truename);
	$mobile		=htmlspecialchars($mobile);
	$address		= htmlspecialchars($address);
	$post_time=time();

	//更新用户信息

	$sql2="update  `#@__user` set school='$school',truename='$truename',mobile='$mobile',address='$address'  where id=$uid";

	$dosql->ExecNoneQuery($sql2);
	
	//判读crm是否是否有记录
	$crm_arr=$dosql->GetOne("select * from `#@__crm`  where uid='$uid'  ");
	if(is_array($crm_arr) && isset($crm_arr['id']) ){
		if($crm_arr['checkinfo']=='false'){
			$dosql->ExecNoneQuery("update  `#@__crm` set school='$school',truename='$truename',mobile='$mobile',address='$address'  where uid=$uid");
		}
	}else{
		//写入crm 
			$dosql->ExecNoneQuery("INSERT INTO  `#@__crm` (school, truename, mobile, address, addtime, checkinfo,uid) VALUES ( '$school','$truename', '$mobile', '$address', '$post_time', 'false','$uid')");
			
	}
	
	
			echo '<script type="text/javascript">
			$.toast("操作成功", function() {
				 window.location.href="'.$calurl.'";
				});
			</script>';
			exit();
}

 

 ?>   

    

<?php require_once('footer.php'); ?>